package com.ctgu.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ctgu.common.ResponseResult;
import com.ctgu.model.entity.Company;
import com.ctgu.model.entity.Employee;
import com.ctgu.model.entity.Evaluate;
import com.ctgu.model.entity.LoginUser;
import com.ctgu.service.ICompanyService;
import com.ctgu.service.impl.CompanyServiceImpl;
import com.ctgu.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yiMa
 * @since 2023-07-05
 */
@RestController
@RequestMapping("/company")
public class CompanyController {
    @Autowired
    private ICompanyService companyService;

    @Autowired
    private CompanyServiceImpl companyServiceImpl;

    @GetMapping("/one")
    @PreAuthorize("@AYM.hasAuthority('company:info:query')")
    public ResponseResult info(Integer id){

        return companyService.getCompanyOne(id);
    }

    /**
     * 公司信息分页查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    @PreAuthorize("@AYM.hasAuthority('company:info:page')")
    public ResponseResult page(int page, int pageSize, String name){
       return companyService.getList(page,pageSize,name);
    }

    @PostMapping("/register")
    public ResponseResult register(@RequestBody Company company){
        return companyService.register(company);
    }

    @PutMapping("/updateInfo")
    @PreAuthorize("@AYM.hasAuthority('company:info:update')")
    public ResponseResult updateInfo(@RequestBody Company company){
        return companyServiceImpl.updateInfo(company);
    }

    @PostMapping("/setEmpState")
    @PreAuthorize("@AYM.hasAuthority('employee:work:update')")
    public ResponseResult setEmpState(@RequestBody Integer[] ids){
        return companyServiceImpl.setEmpState(ids);
    }

    @PostMapping("/evaluate")
    @PreAuthorize("@AYM.hasAuthority('evaluate:one:employee')")
    public ResponseResult evaluate(@RequestBody Evaluate evaluate){
        return companyService.evaluate(evaluate);
    }

    @PostMapping("/uploadExcel")
    @ResponseBody
    @PreAuthorize("@AYM.hasAuthority('employee:uploadExcel:add')")
    public ResponseResult uploadExcel(@RequestParam("file") MultipartFile file) {
        return companyService.uploadExcel(file);
    }


}

